﻿using System.IO;
using System.Linq;

using Microsoft.WowAddonStudio.Lua.Loaders;
using Microsoft.WowAddonStudio.Lua.Model;

using NUnit.Framework;

namespace Microsoft.WowAddonStudio.Lua.Tests.Loaders
{
    [TestFixture]
    public class TocDocumentationLoaderTest : DocumentationLoaderTestBase<TocDocumentationLoader<FileStreamProvider>>
    {
        private const string baseTocPath = "Data";

        private DocumentationScope documentationScope;

        [Test]
        public void LoadSingleFileTest()
        {
            LoadTocFile("Tests/LoadSingleFile.toc");

            Assert.AreEqual(0, documentationScope.Declarations.Count());
        }

        [Test]
        public void InlineScriptsTest()
        {
            LoadTocFile("Tests/InlineScripts.toc");

            Assert.IsNotNull(documentationScope.Resolve<Table>("InlineScriptFrame"));
            Assert.IsNotNull(documentationScope.Resolve<Variable>("loaded"));
            Assert.IsNotNull(documentationScope.Resolve<Variable>("frameloaded"));
            Assert.AreEqual(3, documentationScope.Declarations.Count());
        }

        private void LoadTocFile(string tocPath)
        {
            DocumentationLoader = new TocDocumentationLoader<FileStreamProvider>(new FileStreamProvider(Path.Combine(baseTocPath, tocPath)));
            documentationScope = DocumentationLoader.LoadDocumentation();

            Assert.IsNotNull(documentationScope);
        }
    }
}